/**
 *
 * The MIT License
 *
 * Copyright (c) 2009 Noritaka Horio All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 * @author Noritaka Horio 
 * @copyright Copyright (c) 2009 Noritaka Horio All rights reserved.
 * @license The MIT License
 * @version $Rev: 185 $ $Date: 2009-11-07 12:22:46 +0000 (Sat, 07 Nov 2009) $
 * @see http://mootools.net
 * 
 */

var Bridge;
if (!Bridge) Bridge = {};

Bridge.Dialog = {

	windows: new Hash(),

	showInformation: function() {
		if (this.isWindowOpen("information")) { return };

		var properies	= WindowOptions.information;
		var size		= WindowSize.information;
		var info		= WindowFactory.createWindow(properies,size);

		var htmlLoader = new air.HTMLLoader();
		htmlLoader.height = size.height;
		htmlLoader.width = size.width;
		htmlLoader.load(new air.URLRequest("information.html"))
		htmlLoader.visible = true;

		info.stage.addChild(htmlLoader);
		info.title = this.information.name + " - information";
		info.addEventListener(air.Event.CLOSE, WindowMediator.closeWindow.bind(this, ["information"]));
		info.activate();

		this.windows.set("information", info);
	},

	showConfiguration: function() {
		if (this.isWindowOpen("configuration")) { return };

		var properies = WindowOptions.configuration;
		var size = WindowSize.configuration;
		var configuration = WindowFactory.createWindow(properies,size);

		var htmlLoader = new air.HTMLLoader();
		htmlLoader.height = size.height;
		htmlLoader.width = size.width;
		htmlLoader.load(new air.URLRequest("configuration.html"))
		htmlLoader.visible = true;

		configuration.stage.addChild(htmlLoader);
		configuration.title = this.information.name + " - configuration";
		configuration.addEventListener(air.Event.CLOSE, WindowMediator.closeWindow.bind(this, ["configuration"]));
		configuration.activate();

		this.windows.set("configuration", configuration);
	},

	showNotifyDialog: function(prarameters){
		if (this.isWindowOpen("notify")) { return };

		var properies = WindowOptions.notify;
		var size = WindowSize.notify;
		var notify = WindowFactory.createWindow(properies,size);

		var htmlLoader = new air.HTMLLoader();
		htmlLoader.height = size.height;
		htmlLoader.width = size.width;
		htmlLoader.load(new air.URLRequest("notify.html"))
		htmlLoader.visible = true;
		htmlLoader.paintsDefaultBackground = false;
		htmlLoader.addEventListener(air.Event.COMPLETE, WindowMediator.closeNotifyWindow.bind({"loader": htmlLoader}, [prarameters]));

		notify.stage.addChild(htmlLoader);

		var pointX = notify.stage.fullScreenWidth - notify.width - 30;
		var pointY = notify.stage.fullScreenHeight - notify.height - 30;
		notify.x = pointX;
		notify.y = pointY;
		notify.activate();

		var closeDialog = function () {
			notify.close();
			$clear(closeDialog);
		}.periodical(3000);
	},

	isWindowOpen: function(name) {
		return this.windows.has(name);
	},

	closeWindow: function(name) {
		this.windows.erase(name);
	}
};
